:javascript
  function mirror(textarea, contentType, options) {
    $textarea = $(textarea);
    if ($textarea.val() != '') {
      if(contentType.indexOf('json') >= 0) {
        $textarea.val(JSON.stringify(JSON.parse($textarea.val()), undefined, 2));
        options.json = true;
        options.mode = 'javascript';
      } else if (contentType.indexOf('javascript') >= 0) {
        options.mode = 'javascript';
      } else if (contentType.indexOf('xml') >= 0) {
        options.mode = 'xml';
      } else {
        options.mode = 'htmlmixed';
      }
    }
    return CodeMirror.fromTextArea(textarea, options);
  };

  $(function(){
    $(".request .body .content").each(function(i, el) {
      el = $(el);
      mirror(el.find("textarea")[0], el.data("content-type"), { "readOnly": true, "lineNumbers": true });
    });
  });

%h1== #{example["resource"]} API
.article
  %h2= example["description"]

  - if example["explanation"]
    %p.explanation
      = example["explanation"]

  - if example["parameters"].count > 0
    %h3 Parameters
    %table.parameters
      %thead
        %tr
          %th Name
          %th Description
      %tbody
        - example["parameters"].each do |param|
          %tr.parameter
            %td
              %span.name= param["name"]
            %td
              %span.description= param["description"]

  - example["requests"].each_with_index do |request, index|
    .request{ :id => "request-#{index}" }
      %h3 Request

      %section.headers
        %h4 Headers
        %pre.headers
          :ruby
            # There are unwanted indents if this was a simple each and output in haml
            headers = request["request_headers"].map do |header, value|
              "#{header}: #{value}"
            end
          :preserve
            #{headers.join("\n")}

      %section.route
        %h4 Route
        %pre.route.highlight== #{request["request_method"]} #{request["request_path"]}

      - if !request["request_query_parameters"].empty?
        %section.query-parameters
          %h4 Query Parameters
          %pre.query-parameters.highlight
            = request["request_query_parameters"].map { |k,v| "#{k}=#{v}" }.join("\n")

      - if request["request_body"]
        %section.body
          %h4 Body
          .content{ "data-content-type" => request["request_content_type"] }
            %textarea
              :preserve
                #{request["request_body"]}

      - if request["curl"]
        %section.curl
          %h4 cURL
          %pre= request["curl"]

      - if request["response_status"]
        .response
          %h3 Response

          %section.headers
            %h4 Headers
            %pre.headers
              :ruby
                # There are unwanted indents if this was a simple each and output in haml
                headers = request["response_headers"].map do |header, value|
                  "#{header}: #{value}"
                  end
              :preserve
                #{headers.join("\n")}

          %section.status
            %h4 Status
            %pre.status= request["response_status"]

          - if request["response_body"]
            %section.body
              %h4 Body
              .content{ "data-content-type" => request["response_content_type"] }
                %textarea
                  :preserve
                    #{request["response_body"]}
